Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refactor notify triager workflow #3403

Closed
wants to merge 12 commits into from

Conversation

sambhavgupta0705
Copy link
Member

@sambhavgupta0705 sambhavgupta0705 commented Nov 17, 2024

ref : #3214

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced the triager extraction process to ensure accurate identification of document and code triagers.
    • Added checks to prevent unnecessary review assignments when no triagers are found.
  • Improvements

    • Improved workflow efficiency by streamlining the process of adding reviewers and enhancing the handling of commit messages.
    • Simplified conditions for determining reviewer assignments based on file changes.
    • Updated the CODEOWNERS file to modify owner listings and comment formatting.

Copy link

coderabbitai bot commented Nov 17, 2024

Warning

Rate limit exceeded

@sambhavgupta0705 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 38 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 541568c and 5268cfb.

📒 Files selected for processing (1)
  • .github/workflows/notify-triager.yml (5 hunks)

Walkthrough

The pull request modifies the .github/workflows/notify-triager.yml workflow file to enhance the handling of commit messages and streamline the process of adding reviewers. Key updates include improvements to how commit messages are cleaned and retrieved, simplifications in checking for merge commits, and updates to the extraction of document and code triagers from the CODEOWNERS file. Additionally, the conditions for adding reviewers have been refined to rely solely on file changes.

Changes

File Change Summary
.github/workflows/notify-triager.yml Improved commit message handling, simplified merge commit check, enhanced triager extraction using grep, and refined conditions for adding reviewers.
CODEOWNERS Commented out existing lines, modified owner list for documentation triagers, and retained the original owners for code triagers.

Possibly related PRs

Suggested labels

autoapproved, autoupdate

Suggested reviewers

  • anshgoyalevil
  • derberg
  • magicmatatjahu

Poem

In the code where triagers dwell,
A rabbit hops, all is well.
With checks in place, no calls to waste,
The workflow's smooth, a joyful haste!
Let's cheer for changes, bright and clear,
For every triager, we hold dear! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Nov 17, 2024

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 5268cfb
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/6756d85b34746c0008ed75f3
😎 Deploy Preview https://deploy-preview-3403--asyncapi-website.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@sambhavgupta0705
Copy link
Member Author

sambhavgupta0705 commented Nov 17, 2024

This is currently in draft state

Copy link

codecov bot commented Nov 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.18%. Comparing base (949f520) to head (55a0c57).
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3403      +/-   ##
==========================================
+ Coverage   67.77%   70.18%   +2.40%     
==========================================
  Files          21       21              
  Lines         664      664              
==========================================
+ Hits          450      466      +16     
+ Misses        214      198      -16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@asyncapi-bot
Copy link
Contributor

asyncapi-bot commented Nov 17, 2024

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 45
🟢 Accessibility 98
🟢 Best practices 92
🟢 SEO 100
🔴 PWA 33

Lighthouse ran on https://deploy-preview-3403--asyncapi-website.netlify.app/

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (1)
.github/workflows/notify-triager.yml (1)

73-86: Add error handling for GitHub API calls

The current implementation doesn't handle API failures or rate limits.

 if [ ${#codeTriagers[@]} -gt 0 ]; then
   reviewers=$(printf ', "%s"' "${codeTriagers[@]}")
   reviewers="[${reviewers:2}]"
-  curl \
-    -X POST \
-    -H "Authorization: token ${{ secrets.GH_TOKEN }}" \
-    -H "Accept: application/vnd.github.v3+json" \
-    https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers \
-    -d "{
-      \"reviewers\": $reviewers
-    }"
+  response=$(curl -s -w "%{http_code}" \
+    -X POST \
+    -H "Authorization: token ${{ secrets.GH_TOKEN }}" \
+    -H "Accept: application/vnd.github.v3+json" \
+    https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers \
+    -d "{\"reviewers\": $reviewers}")
+  status_code=${response: -3}
+  if [ $status_code -ge 400 ]; then
+    echo "::error::Failed to add reviewers. Status code: $status_code"
+    exit 1
+  fi
 fi
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 384da22 and 9758be5.

📒 Files selected for processing (1)
  • .github/workflows/notify-triager.yml (1 hunks)
🧰 Additional context used
🪛 actionlint
.github/workflows/notify-triager.yml

62-62: shellcheck reported issue in this script: SC2086:info:5:38: Double quote to prevent globbing and word splitting

(shellcheck)

🪛 yamllint
.github/workflows/notify-triager.yml

[error] 105-105: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (1)
.github/workflows/notify-triager.yml (1)

54-57: Verify CODEOWNERS file format and current triager assignments

Let's ensure the changes align with the current CODEOWNERS file structure.

Also applies to: 63-66

✅ Verification successful

The CODEOWNERS file format and triager assignments are correctly handled

The verification confirms that:

  • The CODEOWNERS file exists and contains the expected triager definitions
  • The #docTriagers line is present with the correct format: #docTriagers: TRohit20 BhaswatiRoy VaishnaviNandakumar J0SAL
  • The code in the workflow correctly extracts triagers using grep '^#docTriagers' and sed 's/#docTriagers: //'
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify CODEOWNERS file format and current triager assignments

# Check if CODEOWNERS file exists and show its content
if [ -f "CODEOWNERS" ]; then
  echo "=== Current CODEOWNERS content ==="
  cat CODEOWNERS
else
  echo "CODEOWNERS file not found"
fi

# Check current triager line format
echo -e "\n=== Current triager definitions ==="
grep -E '^\s*#(doc|code)Triagers:' CODEOWNERS || echo "No triager definitions found"

Length of output: 1243

Comment on lines 54 to 57
docTriagers=$(grep '^#docTriagers' CODEOWNERS | sed 's/#docTriagers: //')
if [ -z "$docTriagers" ]; then
echo "No doc triagers found"
fi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve robustness of triager extraction

The current implementation could be made more robust to handle edge cases:

- docTriagers=$(grep '^#docTriagers' CODEOWNERS | sed 's/#docTriagers: //')
+ docTriagers=$(grep -E '^\s*#docTriagers:' CODEOWNERS | sed 's/^\s*#docTriagers:\s*//' | tr -d '\r')
- codeTriagers=$(grep '^#codeTriagers' CODEOWNERS | sed 's/#codeTriagers: //')
+ codeTriagers=$(grep -E '^\s*#codeTriagers:' CODEOWNERS | sed 's/^\s*#codeTriagers:\s*//' | tr -d '\r')

Changes:

  1. Added \s* to handle potential whitespace before/after the prefix
  2. Added tr -d '\r' to handle CRLF line endings
  3. Used -E for extended regex support

Also applies to: 63-66

Comment on lines 92 to 105
if [ ${#docTriagers[@]} -gt 0 ]; then
reviewers=$(printf ', "%s"' "${docTriagers[@]}")
reviewers="[${reviewers:2}]"
curl \
-X POST \
-H "Authorization: token ${{ secrets.GH_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers \
-d "{
\"reviewers\": $reviewers
}"
else
echo "No doc triagers found, skipping review assignment"
fi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Reduce code duplication and fix file format

  1. The reviewer assignment logic is duplicated between code and doc segments.
  2. File is missing a newline at the end.

Consider extracting the reviewer assignment logic into a reusable function:

+ add_reviewers() {
+   local reviewer_type=$1
+   local reviewers_array=("${@:2}")
+   
+   if [ ${#reviewers_array[@]} -gt 0 ]; then
+     reviewers=$(printf ', "%s"' "${reviewers_array[@]}")
+     reviewers="[${reviewers:2}]"
+     response=$(curl -s -w "%{http_code}" \
+       -X POST \
+       -H "Authorization: token ${{ secrets.GH_TOKEN }}" \
+       -H "Accept: application/vnd.github.v3+json" \
+       https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers \
+       -d "{\"reviewers\": $reviewers}")
+     status_code=${response: -3}
+     if [ $status_code -ge 400 ]; then
+       echo "::error::Failed to add $reviewer_type reviewers. Status code: $status_code"
+       exit 1
+     fi
+   else
+     echo "No $reviewer_type triagers found, skipping review assignment"
+   fi
+ }
+ 
  # Add code reviewers
  IFS=' ' read -r -a codeTriagers <<< "${{ env.codeTriagers }}"
- if [ ${#codeTriagers[@]} -gt 0 ]; then
-   # ... existing code ...
- fi
+ add_reviewers "code" "${codeTriagers[@]}"
  
  # Add doc reviewers
  IFS=' ' read -r -a docTriagers <<< "${{ env.docTriagers }}"
- if [ ${#docTriagers[@]} -gt 0 ]; then
-   # ... existing code ...
- fi
+ add_reviewers "doc" "${docTriagers[@]}"
+
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [ ${#docTriagers[@]} -gt 0 ]; then
reviewers=$(printf ', "%s"' "${docTriagers[@]}")
reviewers="[${reviewers:2}]"
curl \
-X POST \
-H "Authorization: token ${{ secrets.GH_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers \
-d "{
\"reviewers\": $reviewers
}"
else
echo "No doc triagers found, skipping review assignment"
fi
add_reviewers() {
local reviewer_type=$1
local reviewers_array=("${@:2}")
if [ ${#reviewers_array[@]} -gt 0 ]; then
reviewers=$(printf ', "%s"' "${reviewers_array[@]}")
reviewers="[${reviewers:2}]"
response=$(curl -s -w "%{http_code}" \
-X POST \
-H "Authorization: token ${{ secrets.GH_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers \
-d "{\"reviewers\": $reviewers}")
status_code=${response: -3}
if [ $status_code -ge 400 ]; then
echo "::error::Failed to add $reviewer_type reviewers. Status code: $status_code"
exit 1
fi
else
echo "No $reviewer_type triagers found, skipping review assignment"
fi
}
# Add code reviewers
IFS=' ' read -r -a codeTriagers <<< "${{ env.codeTriagers }}"
add_reviewers "code" "${codeTriagers[@]}"
# Add doc reviewers
IFS=' ' read -r -a docTriagers <<< "${{ env.docTriagers }}"
add_reviewers "doc" "${docTriagers[@]}"
🧰 Tools
🪛 yamllint

[error] 105-105: no new line character at the end of file

(new-line-at-end-of-file)

@asyncapi-bot asyncapi-bot added the bounty AsyncAPI Bounty program related label label Nov 18, 2024
@aeworxet
Copy link
Contributor

@asyncapi/bounty_team

@anshgoyalevil
Copy link
Member

@sambhavgupta0705 Is it ready for review?

@sambhavgupta0705
Copy link
Member Author

@anshgoyalevil nope
Will update it by next week

Copy link
Collaborator

@TRohit20 TRohit20 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello there @sambhavgupta0705
I see you made some changes since the last changes, is this PR ready for review now?

Copy link
Member

@anshgoyalevil anshgoyalevil Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the previous implementation of notify traiger workflow, we were getting doc triagers assigned to the PRs that didn't contain any doc changes. This was because of how the workflow was checking for file changes in the PR.

For example, in previous implementation:

  • User A created a PR P1 with code changes. -> Only code triagers assigned to the PR
  • User B created a PR P2 with doc changes. -> Only doc triagers assigned to the PR
  • PR P2 gets merged first.
  • PR P1 is updated to include a merge commit containing PR P2 changes -> Doc traigers also gets assigned to this PR P1. Now this is the part where we are going wrong. Also, this behavior is still ambigious

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was because of MD file changes

@sambhavgupta0705
Copy link
Member Author

Hey
just finished my endsem examination
will be updating this PR by today.
Sorry wasn't able to manage time

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
.github/workflows/notify-triager.yml (1)

Line range hint 1-15: Security: Review workflow permissions and checkout configuration

The workflow has potential security concerns:

  1. Using pull_request_target with PR head checkout can expose repository secrets to malicious PRs
  2. Downgrading actions/checkout from v4.1.1 to v4 might miss security fixes

Consider these changes:

  1. Add explicit permissions block to limit workflow scope
  2. Use specific version v4.1.1 instead of v4
  3. Add input validation before using PR data
name: Notify Triagers

on:
  pull_request_target:
    types: [opened, reopened, synchronize, edited, ready_for_review]

+permissions:
+  pull-requests: write
+  contents: read

jobs:
  Notify-triagers:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repository
-        uses: actions/checkout@v4
+        uses: actions/[email protected]
🧰 Tools
🪛 actionlint (1.7.4)

19-19: shellcheck reported issue in this script: SC2086:info:2:44: Double quote to prevent globbing and word splitting

(shellcheck)


25-25: shellcheck reported issue in this script: SC2193:warning:1:35: The arguments to this comparison can never be equal. Make sure your syntax is correct

(shellcheck)


25-25: shellcheck reported issue in this script: SC2086:info:2:32: Double quote to prevent globbing and word splitting

(shellcheck)


25-25: shellcheck reported issue in this script: SC2086:info:4:33: Double quote to prevent globbing and word splitting

(shellcheck)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9758be5 and c44dbec.

📒 Files selected for processing (1)
  • .github/workflows/notify-triager.yml (2 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/notify-triager.yml

19-19: shellcheck reported issue in this script: SC2086:info:2:44: Double quote to prevent globbing and word splitting

(shellcheck)


25-25: shellcheck reported issue in this script: SC2193:warning:1:35: The arguments to this comparison can never be equal. Make sure your syntax is correct

(shellcheck)


25-25: shellcheck reported issue in this script: SC2086:info:2:32: Double quote to prevent globbing and word splitting

(shellcheck)


25-25: shellcheck reported issue in this script: SC2086:info:4:33: Double quote to prevent globbing and word splitting

(shellcheck)


54-54: shellcheck reported issue in this script: SC2086:info:2:38: Double quote to prevent globbing and word splitting

(shellcheck)

🔇 Additional comments (2)
.github/workflows/notify-triager.yml (2)

48-57: Improve robustness of triager extraction

The previous review comment's solution for handling edge cases in triager extraction is still applicable here. The current awk implementation might miss edge cases with whitespace or line endings.

🧰 Tools
🪛 actionlint (1.7.4)

48-48: shellcheck reported issue in this script: SC2086:info:2:36: Double quote to prevent globbing and word splitting

(shellcheck)


54-54: shellcheck reported issue in this script: SC2086:info:2:38: Double quote to prevent globbing and word splitting

(shellcheck)


58-80: ⚠️ Potential issue

Add error handling for GitHub API calls

The current implementation doesn't handle API failures, which could lead to silent failures.

Add error handling:

      - name: Add Reviewers for code files
        if: env.isMergeCommit == 'false' && steps.non-md-pr-changes.outputs.any_changed == 'true'
        run: |
          IFS=' ' read -r -a codeTriagers <<< "${{ env.codeTriagers }}"
          reviewers=$(printf ', "%s"' "${codeTriagers[@]}")
          reviewers=[${reviewers:2}]
-          curl -X POST \
-            -H "Authorization: token ${{ secrets.GH_TOKEN }}" \
-            -H "Accept: application/vnd.github.v3+json" \
-            https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers \
-            -d "{\"reviewers\": $reviewers}"
+          response=$(curl -s -w "%{http_code}" \
+            -X POST \
+            -H "Authorization: token ${{ secrets.GH_TOKEN }}" \
+            -H "Accept: application/vnd.github.v3+json" \
+            "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers" \
+            -d "{\"reviewers\": $reviewers}")
+          status_code=${response: -3}
+          if [ "$status_code" -ge 400 ]; then
+            echo "::error::Failed to add code reviewers. Status code: $status_code"
+            exit 1
+          fi

The previous review comment's solution for reducing code duplication between doc and code reviewer assignment is still applicable here.

Comment on lines 19 to 30
run: |
commit_message=$(git log --format=%B -n 1 ${{ github.event.pull_request.head.sha }})
echo "commit_message=$commit_message" >> $GITHUB_OUTPUT
commit_message=$(git log --format=%B -n 1 "${{ github.event.pull_request.head.sha }}")
echo "commit_message=${commit_message}" >> $GITHUB_ENV

- name: Check if last commit is a merge commit
id: check-merge-branch
run: |
if [[ "${{ steps.commit-message.outputs.commit_message }}" == *"Merge branch"* ]]; then
echo "Last commit is a merge commit"
echo "isMergeCommit=true" >> $GITHUB_OUTPUT
if [[ "${{ env.commit_message }}" == *"Merge branch"* ]]; then
echo "isMergeCommit=true" >> $GITHUB_ENV
else
echo "Last commit message does not contain Merge branch"
echo "isMergeCommit=false" >> $GITHUB_OUTPUT
echo "isMergeCommit=false" >> $GITHUB_ENV
fi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve shell script robustness and merge detection

The shell script has several areas for improvement:

  1. Missing quotes around variables (flagged by shellcheck)
  2. Merge detection could miss other merge patterns

Apply these improvements:

      - name: Get commit message
        id: commit-message
        run: |
-          commit_message=$(git log --format=%B -n 1 "${{ github.event.pull_request.head.sha }}")
-          echo "commit_message=${commit_message}" >> $GITHUB_ENV
+          commit_message="$(git log --format=%B -n 1 "${{ github.event.pull_request.head.sha }}")"
+          echo "commit_message=${commit_message}" >> "$GITHUB_ENV"

      - name: Check if last commit is a merge commit
        id: check-merge-branch
        run: |
-          if [[ "${{ env.commit_message }}" == *"Merge branch"* ]]; then
-            echo "isMergeCommit=true" >> $GITHUB_ENV
+          if git rev-parse --verify "${{ github.event.pull_request.head.sha }}^2" >/dev/null 2>&1; then
+            echo "isMergeCommit=true" >> "$GITHUB_ENV"
           else
-            echo "isMergeCommit=false" >> $GITHUB_ENV
+            echo "isMergeCommit=false" >> "$GITHUB_ENV"
           fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
run: |
commit_message=$(git log --format=%B -n 1 ${{ github.event.pull_request.head.sha }})
echo "commit_message=$commit_message" >> $GITHUB_OUTPUT
commit_message=$(git log --format=%B -n 1 "${{ github.event.pull_request.head.sha }}")
echo "commit_message=${commit_message}" >> $GITHUB_ENV
- name: Check if last commit is a merge commit
id: check-merge-branch
run: |
if [[ "${{ steps.commit-message.outputs.commit_message }}" == *"Merge branch"* ]]; then
echo "Last commit is a merge commit"
echo "isMergeCommit=true" >> $GITHUB_OUTPUT
if [[ "${{ env.commit_message }}" == *"Merge branch"* ]]; then
echo "isMergeCommit=true" >> $GITHUB_ENV
else
echo "Last commit message does not contain Merge branch"
echo "isMergeCommit=false" >> $GITHUB_OUTPUT
echo "isMergeCommit=false" >> $GITHUB_ENV
fi
run: |
commit_message="$(git log --format=%B -n 1 "${{ github.event.pull_request.head.sha }}")"
echo "commit_message=${commit_message}" >> "$GITHUB_ENV"
- name: Check if last commit is a merge commit
id: check-merge-branch
run: |
if git rev-parse --verify "${{ github.event.pull_request.head.sha }}^2" >/dev/null 2>&1; then
echo "isMergeCommit=true" >> "$GITHUB_ENV"
else
echo "isMergeCommit=false" >> "$GITHUB_ENV"
fi
🧰 Tools
🪛 actionlint (1.7.4)

19-19: shellcheck reported issue in this script: SC2086:info:2:44: Double quote to prevent globbing and word splitting

(shellcheck)


25-25: shellcheck reported issue in this script: SC2193:warning:1:35: The arguments to this comparison can never be equal. Make sure your syntax is correct

(shellcheck)


25-25: shellcheck reported issue in this script: SC2086:info:2:32: Double quote to prevent globbing and word splitting

(shellcheck)


25-25: shellcheck reported issue in this script: SC2086:info:4:33: Double quote to prevent globbing and word splitting

(shellcheck)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
.github/workflows/notify-triager.yml (1)

102-102: Fix file format issues

The file has formatting issues:

  1. Missing newline at end of file
  2. Trailing spaces on line 102
-          
+
🧰 Tools
🪛 yamllint (1.35.1)

[error] 102-102: no new line character at the end of file

(new-line-at-end-of-file)


[error] 102-102: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c44dbec and 097ad18.

📒 Files selected for processing (1)
  • .github/workflows/notify-triager.yml (4 hunks)
🧰 Additional context used
🪛 yamllint (1.35.1)
.github/workflows/notify-triager.yml

[error] 102-102: no new line character at the end of file

(new-line-at-end-of-file)


[error] 102-102: trailing spaces

(trailing-spaces)

🔇 Additional comments (3)
.github/workflows/notify-triager.yml (3)

Line range hint 28-34: Use git rev-parse for reliable merge commit detection

The current string matching approach for detecting merge commits is unreliable. Using git rev-parse would be more accurate as it checks the actual commit structure.

-          if [[ "${{ steps.commit-message.outputs.commit_message }}" == *"Merge branch"* ]]; then
-            echo "Last commit is a merge commit"
-            echo "isMergeCommit=true" >> $GITHUB_OUTPUT
-          else
-            echo "Last commit message does not contain Merge branch"
-            echo "isMergeCommit=false" >> $GITHUB_OUTPUT
-          fi
+          if git rev-parse --verify "${{ github.event.pull_request.head.sha }}^2" >/dev/null 2>&1; then
+            echo "Last commit is a merge commit"
+            echo "isMergeCommit=true" >> "$GITHUB_OUTPUT"
+          else
+            echo "Last commit is not a merge commit"
+            echo "isMergeCommit=false" >> "$GITHUB_OUTPUT"
+          fi
🧰 Tools
🪛 actionlint (1.7.4)

19-19: shellcheck reported issue in this script: SC2086:info:5:42: Double quote to prevent globbing and word splitting

(shellcheck)


Line range hint 55-71: Improve triager extraction robustness

The current approach using tail and head is fragile as it depends on exact line positions. Let's make it more robust:

       - name: Extract Doc Triage Maintainers
         id: doc-triager
         run: |
-          docTriagers=$(grep '^#' CODEOWNERS | tail -n 2 | head -n 1)
-          echo "docTriagers: $docTriagers"
-          prefix="#docTriagers: "
-          docTriagers=${docTriagers#$prefix}
-          echo "docTriagers=$docTriagers" >> $GITHUB_ENV
+          if [ ! -f CODEOWNERS ]; then
+            echo "::error::CODEOWNERS file not found"
+            exit 1
+          fi
+          if ! docTriagers=$(grep -E '^\s*#docTriagers:' CODEOWNERS | sed 's/^\s*#docTriagers:\s*//' | tr -d '\r'); then
+            echo "::error::Failed to extract doc triagers"
+            exit 1
+          fi
+          echo "docTriagers=$docTriagers" >> "$GITHUB_ENV"

       - name: Extract Code Triage Maintainers
         id: code-triager
         run: |
-          codeTriagers=$(grep '^#' CODEOWNERS | tail -n 1)
-          echo "codeTriagers: $codeTriagers"
-          prefix="#codeTriagers: "
-          codeTriagers=${codeTriagers#$prefix}
-          echo "codeTriagers=$codeTriagers" >> $GITHUB_ENV
+          if ! codeTriagers=$(grep -E '^\s*#codeTriagers:' CODEOWNERS | sed 's/^\s*#codeTriagers:\s*//' | tr -d '\r'); then
+            echo "::error::Failed to extract code triagers"
+            exit 1
+          fi
+          echo "codeTriagers=$codeTriagers" >> "$GITHUB_ENV"

Line range hint 74-102: Reduce duplication and add error handling in reviewer assignment

The reviewer assignment logic is duplicated and lacks error handling for the GitHub API calls.

+      - name: Setup reviewer assignment function
+        run: |
+          add_reviewers() {
+            local reviewer_type=$1
+            local reviewers_array=("${@:2}")
+            
+            if [ ${#reviewers_array[@]} -gt 0 ]; then
+              reviewers=$(printf ', "%s"' "${reviewers_array[@]}")
+              reviewers="[${reviewers:2}]"
+              response=$(curl -s -w "%{http_code}" \
+                -X POST \
+                -H "Authorization: token ${{ secrets.GH_TOKEN }}" \
+                -H "Accept: application/vnd.github.v3+json" \
+                "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers" \
+                -d "{\"reviewers\": $reviewers}")
+              status_code=${response: -3}
+              if [ $status_code -ge 400 ]; then
+                echo "::error::Failed to add $reviewer_type reviewers. Status code: $status_code"
+                exit 1
+              fi
+            else
+              echo "No $reviewer_type triagers found, skipping review assignment"
+            fi
+          }

       - name: Add Reviewers for code files
         if: steps.non-md-pr-changes.outputs.any_changed == 'true'
         run: |
           IFS=' ' read -r -a codeTriagers <<< "${{ env.codeTriagers }}"
-          reviewers=$(printf ', "%s"' "${codeTriagers[@]}")
-          reviewers=[${reviewers:2}]
-          curl \
-          -X POST \
-          -H "Authorization: token ${{ secrets.GH_TOKEN }}" \
-          -H "Accept: application/vnd.github.v3+json" \
-          https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers \
-          -d "{
-            \"reviewers\": $reviewers
-          }"
+          add_reviewers "code" "${codeTriagers[@]}"

       - name: Add Reviewers for doc files
         if: steps.md-pr-changes.outputs.any_changed == 'true'
         run: |
           IFS=' ' read -r -a docTriagers <<< "${{ env.docTriagers }}"
-          reviewers=$(printf ', "%s"' "${docTriagers[@]}")
-          reviewers=[${reviewers:2}]
-          curl \
-          -X POST \
-          -H "Authorization: token ${{ secrets.GH_TOKEN }}" \
-          -H "Accept: application/vnd.github.v3+json" \
-          https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/requested_reviewers \
-          -d "{
-            \"reviewers\": $reviewers
-          }"
+          add_reviewers "doc" "${docTriagers[@]}"

Comment on lines +20 to +23
# Extract the commit message
commit_message=$(git log --format=%B -n 1 ${{ github.event.pull_request.head.sha }})
commit_message=$(echo "$commit_message" | tr '\n' ' ')
commit_message=$(echo "$commit_message" | sed 's/[<>|]//g' | sed 's/[][]//g' | sed 's/(//g' | sed 's/)//g' | xargs)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve commit message extraction robustness and efficiency

The commit message extraction and cleaning can be improved for better robustness and efficiency.

-          commit_message=$(git log --format=%B -n 1 ${{ github.event.pull_request.head.sha }})
-          commit_message=$(echo "$commit_message" | tr '\n' ' ')
-          commit_message=$(echo "$commit_message" | sed 's/[<>|]//g' | sed 's/[][]//g' | sed 's/(//g' | sed 's/)//g' | xargs)
+          if ! commit_message=$(git log --format=%B -n 1 "${{ github.event.pull_request.head.sha }}"); then
+            echo "::error::Failed to extract commit message"
+            exit 1
+          fi
+          commit_message=$(echo "$commit_message" | tr '\n' ' ' | sed 's/[<>|()[\]]//g' | xargs)
           echo "commit_message=$commit_message" >> $GITHUB_OUTPUT

Changes:

  1. Added quotes around GitHub SHA to prevent word splitting
  2. Added error handling for git log command
  3. Combined multiple sed commands into one for better efficiency
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Extract the commit message
commit_message=$(git log --format=%B -n 1 ${{ github.event.pull_request.head.sha }})
commit_message=$(echo "$commit_message" | tr '\n' ' ')
commit_message=$(echo "$commit_message" | sed 's/[<>|]//g' | sed 's/[][]//g' | sed 's/(//g' | sed 's/)//g' | xargs)
# Extract the commit message
if ! commit_message=$(git log --format=%B -n 1 "${{ github.event.pull_request.head.sha }}"); then
echo "::error::Failed to extract commit message"
exit 1
fi
commit_message=$(echo "$commit_message" | tr '\n' ' ' | sed 's/[<>|()[\]]//g' | xargs)
echo "commit_message=$commit_message" >> $GITHUB_OUTPUT

@sambhavgupta0705
Copy link
Member Author

closing it for sometime as I am doing testing on this

@asyncapi-bot asyncapi-bot removed the bounty AsyncAPI Bounty program related label label Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants